#include <hgPainterAbstract.h>

using namespace hg;


void PainterAbstract::line(const Vec2& begin, const Vec2& end, const Color& col, float lineWidth)
{
	addPathPoint(begin);
	addPathPoint(end);
	flushLine(col, false, lineWidth);
}
void PainterAbstract::rect(const Rect& rect, const Color& col, bool full, float lineWidth)
{
	addPathPoint(Vec2(rect.minPos.x, rect.minPos.y));
	addPathPoint(Vec2(rect.minPos.x, rect.maxPos.y));
	addPathPoint(Vec2(rect.maxPos.x, rect.maxPos.y));
	addPathPoint(Vec2(rect.maxPos.x, rect.minPos.y));
	if (full) flushFull(col, lineWidth);
	else flushLine(col, true, lineWidth);
}
void PainterAbstract::round(const Vec2& pos, float r, const Color& col, bool full, float seg, float lineWidth)
{
	float t = 0.0f;
	for (int i = 0; i < seg; ++i)
	{
		t = HG_PI2 / seg * i;
		addPathPoint(pos + Vec2(r * cos(t), r * sin(t)));
	}
	if (full) flushFull(col, lineWidth);
	else flushLine(col, true, lineWidth);
}
void PainterAbstract::arc(const Vec2& pos, float r, float beginAngle, float offset, const Color& col, bool full, float lineWidth)
{
	float beg = Math::getInstance()->range(beginAngle);
	float offsetAngle = Math::getInstance()->range(offset);
	if (offsetAngle < 1.0f) return;
	float keyPointNum = offsetAngle * 0.1f;
	float totalAngle = offsetAngle / keyPointNum;
	for (int i = 0; i < keyPointNum; ++i)
		addPathPoint(Vec2(pos.x + r * cos(Math::getInstance()->angleToRadian(beginAngle + totalAngle * i)),
			pos.y + r * sin(Math::getInstance()->angleToRadian(beginAngle + totalAngle * i))));
	if (full) flushFull(col, lineWidth);
	else flushLine(col, true, lineWidth);
}
void PainterAbstract::mat(const Mat3& mat, const Color& col, bool full, float lineWidth)
{
	addPathPoint(Vec2(0.5f, -0.5f) * mat);
	addPathPoint(Vec2(0.5f, 0.5f) * mat);
	addPathPoint(Vec2(-0.5f, 0.5f) * mat);
	addPathPoint(Vec2(-0.5f, -0.5f) * mat);
	if (full) flushFull(col, lineWidth);
	else flushLine(col, true, lineWidth);
}
void PainterAbstract::coord(const Vec2& pos, float angle, bool flipX, bool flipY, float length, float lineWidth)
{
	addPathPoint(pos);
	addPathPoint(pos + Math::getInstance()->dirVec(angle) * length * (flipX ? -1.0f : 1.0f));
	flushLine(0xff0000ff, false, lineWidth);
	addPathPoint(pos);
	addPathPoint(pos + Math::getInstance()->dirVec(angle + 90.0f) * length * (flipY ? -1.0f : 1.0f));
	flushLine(0x00ff00ff, false, lineWidth);
}


